<template>
	<view class="content">
		<navTop :title="navtop.title" :tipsShow="false" :color="navtop.color" :isBack="false" ></navTop>
		<view class="content-center">
			<view class="view-top">
				<image :src="banner" mode="" class="view-top__img"></image>
				<view class="view-top__title">
					<image :src="userInfo.head || wxInfo.avatarUrl" mode="" class="view-user__img"></image>
					<view class="view-user__center">
						<view class="flex-l">
							<text class="view-sex__text">{{userInfo.name || wxInfo.nikeName || ''}}</text>
							<image v-if="userInfo.gender == 1" :src="me_male" mode="" class="view-sex__img"></image>
							<image v-if="userInfo.gender == 2" :src="me_list_female" mode="" class="view-sex__img"></image>
						</view>
						<view class="view-sex__text-info">
							{{userInfo.location || wxInfo.city || ' '}}
						</view>
						<view class="view-nums">
							<view class="view-nums__item">
								<view class="view-nums__item-num">
									{{staticInfo.posts || 0}}
								</view>
								<view class="view-nums__item-title">
									Posts
								</view>
							</view>
							<view class="view-nums__item" @click="gotoFollow(0)">
								<view class="view-nums__item-num">
									{{staticInfo.following || 0}}
								</view>
								<view class="view-nums__item-title">
									Following
								</view>
							</view>
							<view class="view-nums__item" @click="gotoFollow(1)">
								<view class="view-nums__item-num">
									{{staticInfo.follower || 0}}
								</view>
								<view class="view-nums__item-title">
									Follower
								</view>
							</view>
						</view>
					</view>
					<view class="view-user__btn" @click="gotoPage('/pages/me/edit')">
						<image :src="editPng" mode="" class="view-user__btn-img"></image>
						Edit
					</view>
				</view>
				<view class="view-top__nav">
				</view>
			</view>
			<view class="view-content">
				<view class="view-content__1">
					<view class="title">
						My Posts
					</view>
					<view class="flex-b">
						<view class="content-item" v-for="(v, i) in contentList" :key="i" @click="gotoPage(`/pages/me/myPost?type=${i}`)">
							<image :src="v.img" mode="" class="content-item__img"></image>
							<view>{{v.text}}</view>
							<view class="content-item__number" v-if="v.number">
								{{v.number || 0}}
							</view>
						</view>
					</view>
				</view>
				<view class="view-content__2">
					<view class="view-list__line" v-for="(v, i) in lines"  :key="i" @click="gotoLinePage(v, i)">
						<view class="flex-l">
							<image :src="v.img" mode="" class="line-img"></image>
							<text>{{v.text}}</text>
						</view>
						<view class="flex-l">
							<text class="line-num">{{v.info}}</text>
							<image :src="vDown" mode="" class="line-right"></image>
						</view>
					</view>
				</view>
			</view>
			
			<view class="not-login__view" :style="{'top': isLogin ? '120vh': '0'}">
				<image :src="'/static/logo.jpg'" mode="" class="app-img"></image>
				<view class="app-name">龙华online</view>
				<view class="app-info">This is a slogan</view>
				<button class="login-btn" open-type="getUserInfo" withCredentials="true" lang="zh_CN" @getuserinfo="wxGetUserInfo">
					授权微信登录
				</button>
			</view>
		</view>
		<customTarbar :selectIndex="3" />
	</view>
</template>
<script>
import navTop from '@/components/nav-title.vue';
import customTarbar from '@/components/custom-tarbar.vue';

import banner from '@/static/me_banner.png'
import vDown from '@/static/v-down.png'
import me_edit from '@/static/me_edit.png'
import me_male from '@/static/me_male.png'
import me_list_female from '@/static/me_list_female.png'
import me_await from '@/static/me_await.png'
import me_published from '@/static/me_published.png'
import me_rejected from '@/static/me_rejected.png'
import me_like from '@/static/me_like.png'
import me_setting from '@/static/me_setting.png'
import me_list_edit from '@/static/me_list_edit.png'
import editPng from '@/static/edit.png'
import logo from '@/static/logo.jpg'

	export default {
		components: {
			navTop,
			customTarbar
		},
		data() {
			return {
				editPng,
				me_like,
				me_setting,
				me_list_edit,
				me_list_female,
				banner,
				vDown,
				me_edit,
				me_male,
				me_await,
				me_published,
				me_rejected,
				logo,
				barHeight: 0,
				isLogin: true,
				userInfo: {},
				wxInfo: {},
				staticInfo: {},
				active: 0,
				navtop: {
					title: ' ',
					color: '#024230'
				},
				contentList: [
					{
						img: me_await,
						text: 'Waiting',
						number: 0
					},
					{
						img: me_published,
						text: 'Published',
						number: 0
					},
					{
						img: me_rejected,
						text: 'Rejected',
						number: 0
					}
				],
				lines: [
					{
						img: me_like,
						text: 'Liked',
						info: 0
					},
					{
						img: me_list_edit,
						text: 'FeedBack',
						info: ''
					},
					{
						img: me_setting,
						text: 'Setting',
						info: ''
					}
				]
			}
		},
		onLoad() {
		},
		created() {
			this.isBarHeight999().then((statusBarHeight)=>{
				this.barHeight = statusBarHeight + 100
			})
		},
		onShow() {
			this.wxInfo = uni.getStorageSync("wxInfo") || {}
			this.userInfo = uni.getStorageSync("userInfo") || {}
			this.isLogin = uni.getStorageSync("openId") || ''
			if (this.isLogin) {
				this.initStatic()
				this.initMypost()
			}
		},
		mounted() {
		},
		methods: {
			gotoItem(v, i) {
				this.active = i
			},
			gotoPage(url) {
				uni.navigateTo({
					url: url
				});
			},
			wxGetUserInfo() {
				let _this = this;
				uni.getUserInfo({
					provider: 'weixin',
					success: (infoRes) => {
						this.wxInfo = infoRes.userInfo
						uni.setStorageSync('wxInfo', infoRes.userInfo)
						this.wxLoign()
					},
					fail(res) {}
				});
			},
			wxLoign() {
				uni.showLoading({
					title: '请稍候...'
				})
				uni.login({
				  provider: 'weixin',
				  success: (loginRes) =>  {
					uni.setStorageSync('code', loginRes.code)
					this.$http('post', '/app/getOpenId', {
						code: loginRes.code
					}, {
						'Content-Type': 'application/x-www-form-urlencoded'
					}).then((res) => {
						uni.hideLoading();
						if (res.success) {
							uni.setStorageSync('openId', res.data.openId)
							uni.setStorageSync('userInfo', res.data)
							this.isLogin = true
							this.userInfo = res.data
							if (!res.data.name ||res.data.name == 'null') {
								uni.navigateTo({
									url: '/pages/me/lang'
								});
								return false
							}
							this.initStatic()
							this.initMypost()
						}
					})
				  }
				});
			},
			initStatic() {
				this.$http('get', '/app/me/dynamic/statics').then((res) => {
					if (res.success) {
						this.staticInfo = res.data
					}
				})
			},
			initMypost() {
				this.$http('get', '/app/me/myPosts').then((res) => {
					if (res.success) {
						this.contentList[0].number = res.data.watting || 0
						this.contentList[1].number = res.data.published || 0
						this.contentList[2].number = res.data.rejected || 0
						this.lines[0].info = res.data.liked || 0
					}
				})
			},
			gotoLinePage(v, i) {
				const pages = ['liked', 'feedback', 'setting']
				uni.navigateTo({
					url: '/pages/me/' + pages[i]
				})
			},
			gotoFollow(i) {
				uni.navigateTo({
					url: '/pages/me/follwer?type=' + i
				})
			}
		}
	}
</script>

<style lang="less">
.content {
	background-color: #0078FF;
}
.view-top {
	position: relative;
	.view-top__img {
		width: 100vw;
	}
	.view-top__title {
		position: absolute;
		left: 30rpx;
		top: 176rpx;
		font-size: 64rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #FFFFFF;
		box-sizing: border-box;
		padding-right: 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.view-user__img {
		width: 128rpx;
		height: 128rpx;
		border-radius: 50%;
	}
	.view-user__center{
		width: 396rpx;
		padding: 0 24rpx;
		box-sizing: border-box;
		position: relative;
		.view-sex__text {
			font-size: 48rpx;
			font-family: Helvetica-Bold, Helvetica;
			font-weight: bold;
			color: #FFFFFF;
			margin: 0 16rpx 8rpx 0;
		}
		.view-sex__img {
			width: 32rpx;
			height: 32rpx;
		}
		.view-sex__text-info {
			box-sizing: border-box;
			padding: 6rpx 0 0 18rpx;
			font-size: 26rpx;
			font-family: Helvetica;
			color: #FFFFFF;
		}
		.view-nums {
			position: absolute;
			font-size: 32rpx;
			top: 130rpx;
			left: 0;
			right: 0;
			display: flex;
			box-sizing: border-box;
			padding: 0 30rpx;
			justify-content: space-between;
			align-items: flex-start;
		}
		.view-nums__item {
			text-align: left;
		}
		.view-nums__item-num {
			font-size: 32rpx;
			font-family: Helvetica-Bold, Helvetica;
			font-weight: bold;
			color: #FFFFFF;
			margin-bottom: 10rpx;
		}
		.view-nums__item-title {
			font-size: 22rpx;
			font-family: Helvetica-Light, Helvetica;
			font-weight: 300;
			color: #FFFFFF;
		}
	}
	.view-user__btn{
		display: flex;
		justify-content: center;
		align-items: center;
		width: 142rpx;
		height: 60rpx;
		font-size: 28rpx;
		font-family: Helvetica-Bold, Helvetica;
		font-weight: bold;
		color: #FFFFFF;
		border-radius: 30rpx;
		background: linear-gradient(270deg, #439BFF 0%, #0078FF 100%);
		box-shadow: 0px 4px 16px 0px rgba(0, 120, 255, 0.25);
		.view-user__btn-img {
			width: 32rpx;
			height: 32rpx;
			margin-right: 8rpx;
		}
	}
}

.flex-l {
	display: flex;
	justify-content: flex-start;
	align-items: center;
}

.view-content {
	// margin-top: -40rpx;
	background-color: #fff;
	padding: 0 30rpx;
	position: relative;
	z-index: 9;
}
.view-content__1 {
	background: #FFFFFF;
	box-shadow: 0px 4px 12px 0px rgba(55, 58, 64, 0.08);
	border-radius: 8rpx;
	padding: 40rpx;
	margin-bottom: 24rpx;
	position: absolute;
	left: 30rpx;
	right: 30rpx;
	top: -40rpx;
	.title {
		font-size: 32rpx;
		font-family: Helvetica-Bold, Helvetica;
		font-weight: bold;
		color: #1F1F1F;
		margin-bottom: 40rpx;
	}
}
.flex-b {
	display: flex;
	align-items: center;
	justify-content: space-around;
}
.content-item{
	font-size: 24rpx;
	text-align: center;
	font-family: Helvetica;
	color: rgba(31, 31, 31, 0.65);
	position: relative;
	.content-item__img {
		width: 56rpx;
		height: 56rpx;
		margin-bottom: 22rpx;
	}
	.content-item__number {
		position: absolute;
		right: 0;
		top: 0;
		transform: translate(0, -50%);
		padding: 0 8rpx;
		background-color: #EF4042;
		color: #fff;
		border-radius: 20rpx;
	}
}
.view-content__2 {
	position: absolute;
	left: 30rpx;
	right: 30rpx;
	top: 260rpx;
	padding: 50rpx 40rpx;
	font-size: 32rpx;
	font-family: Helvetica-Bold, Helvetica;
	font-weight: bold;
	color: #1F1F1F;
	background: #FFFFFF;
	box-shadow: 0px 4px 12px 0px rgba(55, 58, 64, 0.08);
	border-radius: 8rpx;
	.view-list__line {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 52rpx;
	}
	.line-img {
		width: 40rpx;
		height: 40rpx;
		margin-right: 18rpx;
	}
	.line-num {
		margin-right: 20rpx;
		color: rgba(31, 31, 31, 0.65);
	}
	.line-right {
		width: 32rpx;
		height: 32rpx;
	}
}
.not-login__view {
	position: fixed;
	top: 120vh;
	height: 100vh;
	width: 100vw;
	left: 0;
	bottom: 140rpx;
	background-color: #fff;
	z-index: 9999;
	text-align: center;
	transition: all 0.3s;
	.app-img {
		width: 400rpx;
		height: 400rpx;
		margin: 15vh auto 0rpx;
	}
	.app-name {
		font-size: 48rpx;
		font-family: Helvetica-Bold, Helvetica;
		font-weight: bold;
		color: #1F1F1F;
		margin-bottom: 16rpx;
		text-align: center;
	}
	.app-info{
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(31, 31, 31, 0.65);
		text-align: center;
	}
	.login-btn {
		margin: 120rpx auto 0;
		width: 480rpx;
		height: 88rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #0078FF;
		border-radius: 28px;
		font-size: 32rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
	}
}

</style>
